import 'dart:io';
import 'package:flutter/material.dart';
import 'package:device_info/device_info.dart';
import 'package:package_info/package_info.dart';

class Device {
  static Device _device;
  static bool _isPhoneX = false;
  static double _topSafeArea = 0;
  static double _bottomSafeArea = 0;
  static double _screenWidth = 0;
  static double _screenHeight = 0;
  static String _idfa;
  static String _appVersion;

  factory Device() {
    return _device;
  }

  Device._internal();

  static void init(BuildContext context) {
    if (_device != null) {
      return;
    }
    _device = Device._internal();
    MediaQueryData mediaQuery = MediaQuery.of(context);
    if (Platform.isIOS) {
      Device._isPhoneX = mediaQuery.padding.bottom > 0;
    }
    _topSafeArea = mediaQuery.padding.top;
    _bottomSafeArea = mediaQuery.padding.bottom;
    _screenHeight = mediaQuery.size.height;
    _screenWidth = mediaQuery.size.width;
    _getDeviceInfo();
  }

  static void _getDeviceInfo() async{
    DeviceInfoPlugin deviceInfo = new DeviceInfoPlugin();
    if(Platform.isIOS){
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
      _idfa = iosInfo.identifierForVendor;
    }else if(Platform.isAndroid){
//      _idfa = '';
    }
    
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    _appVersion = packageInfo.version;
  }

  static bool get isIOS => Platform.isIOS;

  static bool get isAndroid => Platform.isAndroid;

  static bool get isPhoneX => _isPhoneX;

  static double get topSafeArea => _topSafeArea;

  static double get bottomSafeArea => _bottomSafeArea;

//  static double get screenWidth => _screenWidth;
//
//  static double get screenHeight => _screenHeight;

  static String get appVersion => _appVersion;

  static String get idfa => _idfa;

}